import json
from NCHU import NCHU
from mongoModel import louisMongo


def saveCourseInfo(user='Louis', token=None):
    mongo = louisMongo(init=False)
    mongo.DB('Utils')
    mongo.Col('{}Course-2020-9'.format(user))
    mongo = mongo.Get()

    course = NCHU(token=token)
    for i in range(15, 19):
        courseInfoJson = course.courseInfo(week=i)
        print(courseInfoJson)
        courseInfo = json.loads(courseInfoJson)
        temp = str(courseInfo)[1:-1]
        temp = '{' + temp + '}'
        courseInfo = {}
        courseInfo['week'] = str(i)
        courseInfo['data'] = temp
        mongo.insert_one(courseInfo)

if __name__ == '__main__':
    token = "p5aJHzQXN6S7Fn/vpTgx/b1iKNKNINqNVUK325Ftnddyijk8h0VYrVfzYbiIgAQIS2FNd49EWlDKWO/mpuGjPIWEwgLaixuS48OszmTzJxg4vEVGZTseZ0HJ3ZBsRPvzwwIHbrqUbC6qjsizXFH6jZpf2MCSRIrHlEErgjFo3dg="
    user = 'Louis'
    saveCourseInfo(user=user, token=token)